<template>
  <div>
    <el-container>
      <el-header>
        <p><img src="../../public/4.jpg" alt="">电商后台管理系统</p>
        <el-button @click="del">退出</el-button>
      </el-header>
      <!-- 左边栏 -->
      <el-container>
        <el-aside :width="iscollaps ? '85px' : '200px'">
          <div class="iscollaps" @click="iscollaps = !iscollaps">|||</div>
          <el-menu
            :collapse="iscollaps"
            :collapse-transition="false"
            :default-active="$route.path"
            class="el-menu-vertical-demo"
            background-color="#333"
            text-color="#fff"
            router
            active-text-color="#00f"
            :unique-opened="true"
          >
            <el-submenu
              :index="item.id + ''"
              v-for="item in list"
              :key="item.id"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item
                :index="'/' + item2.path"
                v-for="item2 in item.children"
                :key="item2.id"
              >
                <i class="el-icon-menu"></i>
                <span>{{ item2.authName }}</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!-- 右边栏 -->
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { adios } from '@/http/api'
export default {
  data() {
    return {
      list: [],
      iscollaps: false
    }
  },
  created() {
    this.applist()
  },
  methods: {
    async applist() {
      const arr = await adios()
      this.list = arr
    },
    // 退出
    del() {
      sessionStorage.removeItem('token')
      this.$router.replace('/login')
    }
  }
}
</script>

<style lang="less" scoped>
.el-container {
  height: 100%;
}
.el-header {
  display: flex;
  justify-content: space-between;
  background-color: #000;
  color: #fff;
  font-size: 20px;
  align-items: center;
  .el-button {
    height: 38px;
    margin-top: 14px;
  }
  p{
    height: 60px;
    line-height: 60px;
    img{
      width: 30px;
      margin-right: 10px;
    }
  }
}

.el-aside {
  background-color: #333;
  color: #333;
  min-height: 765px;
  .iscollaps {
    color: #fff;
    text-align: center;
    cursor: pointer;
  }
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}
</style>
